﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ProjectCloth.Entity;

namespace ProjectCloth.FrmUI
{
    public partial class AskPriceListFrm : UserControl
    {
        private ClothContext db = new ClothContext();
        public AskPriceListFrm()
        {
            InitializeComponent();
        }
        private void SaveBtn_Click(object sender, EventArgs e)
        {

        }
        private void CancelBtn_Click(object sender, EventArgs e)
        {
            //this.Hide();
        }
        private void dataGridView1_CellEnter(object sender, DataGridViewCellEventArgs e)
        {

        }
        private void QueryBtn_Click(object sender, EventArgs e)
        {
            var startTime = startDatePiker.Value.Date;
            var endTime = endDatePicker.Value.AddDays(1).Date;
            var list = (from a in db.AskPriceOrders.Where(o =>
             (o.Date >= startTime && o.Date < endTime
             && (string.IsNullOrEmpty(CompanyNameTxt.Text) || o.CompanyName.Contains(CompanyNameTxt.Text))
             && (string.IsNullOrEmpty(PhoneTxt.Text) || o.Phone.Contains(PhoneTxt.Text))
             && (string.IsNullOrEmpty(LiaisonTxt.Text) || o.Liaison.Contains(LiaisonTxt.Text))
             && (string.IsNullOrEmpty(ProvinceTxt.Text) || o.Province.Contains(ProvinceTxt.Text))
             && (string.IsNullOrEmpty(ProductNoTxt.Text) || o.ProductNo.Contains(ProductNoTxt.Text))
                       )).ToList()
                        select new
                        {
                            a.Date,
                            a.CompanyName,
                            a.Phone,
                            a.Liaison,
                            a.Province,
                            a.ProductNo,
                            a.ColorType,
                            a.Quantity,
                            a.Factory,
                            a.ProductNoB,
                            a.ProductCost,
                            a.BatchPrice,
                            a.Price,
                            a.Remark
                        }).ToList();
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = list;
        }

        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            //自动编号，与数据无关
            Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
               e.RowBounds.Location.Y,
               dataGridView1.RowHeadersWidth - 4,
               e.RowBounds.Height);
            TextRenderer.DrawText(e.Graphics,
                  (e.RowIndex + 1).ToString(),
                   dataGridView1.RowHeadersDefaultCellStyle.Font,
                   rectangle,
                   dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
                   TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }

        private void ClearBtn_Click(object sender, EventArgs e)
        {
            CompanyNameTxt.Text = "";
            PhoneTxt.Text = "";
            LiaisonTxt.Text = "";
            ProvinceTxt.Text = "";
            dataGridView1.Rows.Clear();
        }
    }
}
